package abq2.jic.jic.plugin.operate.lostandfound;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.list.BillList;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;

import java.util.Date;
import java.util.EventObject;

/**
 * 动态表单插件
 */
public class SearchLAF extends AbstractFormPlugin implements Plugin {

    /**
     * 关于发送评论的相关逻辑
     * @param args
     */
    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
        super.beforeDoOperation(args);
        String operateKey = ((FormOperate) args.getSource()).getOperateKey();
        if (operateKey.equals("searchlaf")) {
            String type = (String) this.getModel().getValue("abq2_combofield");
            if (type == null) {
                type = "";
            }
            String name = (String) this.getModel().getValue("abq2_textfield");

            if (type.equals("") && name.equals("")){
                BillList billList = this.getControl("abq2_billlistap");
                billList.setOrderBy("createtime desc");
                billList.refreshData();
                billList.refresh();
                return;
            }
            BillList billList = this.getControl("abq2_billlistap");
            if (!type.equals("") && name.equals("")) {
                billList.setFilter(new QFilter("abq2_type",QCP.equals,type));
            }
            if (!name.equals("") && type.equals("")) {
                billList.setFilter(new QFilter("abq2_object_name",QCP.like,name));
            }
            if (!name.equals("") && !type.equals("")){
                billList.setFilter(new QFilter("abq2_object_name",QCP.like,name).and(new QFilter("abq2_type",QCP.equals,type)));
            }
            billList.setOrderBy("createtime desc");
            billList.refreshData();
            billList.refresh();
        }
    }
}